package cn.edu.xjtu.competiton.力扣.双周赛.biweekly87;

import java.util.Arrays;

/**
 * @author Hydrion-QLz
 * @date 2022-09-17 22:53
 * @description
 */
public class second {
    public int matchPlayersAndTrainers(int[] players, int[] trainers) {
        Arrays.sort(players);
        Arrays.sort(trainers);
        int playerIdx = 0;
        int trainerIdx = 0;
        int sum = 0;
        while (playerIdx < players.length && trainerIdx < trainers.length) {
            if (players[playerIdx] <= trainers[trainerIdx]) {
                sum++;
                playerIdx++;
                trainerIdx++;
            } else {
                trainerIdx++;
            }
        }
        return sum;
    }
}
